** estimate effects for each cognitive domain 

***Inputs: 
* $Data/GameUserWPdaily_norm.dta
* $Data/maxmindirectionsmonth_zip260.dta


***Outputs: 
* $Results/genderage.png
* $Results/agegender_obs.png

	
	use $Data/GameUserWPdaily_norm.dta, clear
	
	gen month = month(date)

		
	gen zip2 = int( zip/10)
	
	merge m:1 zip2 month using $Data/maxmindirectionsmonth_zip260.dta
	
	keep if _merge ==3
	
	
	gen monthyear = mofd(date)

	gen highpm =  weighted_dailypm > 25 & weighted_dailypm<. 

	
	
	egen cut_winddirection = cut(median_closestwind), at(0(60)360)
	replace cut_winddirection = 0 if median_closestwind ==360

	
	
	gen maxzipwind = (cut_winddirection ==maxdirection )
	replace maxzipwind = . if maxdirection==.
	
	keep if maxzipwind<. 
	
	label variable highpm "Daily PM2.5 $>$ 25" 

		egen cut_temp = cut(weighted_temperature), at(-40(10)40)

		gen under50 = age< 50
		
	

ivreghdfe norm_score (c.highpm#i.male#i.under50  =c.maxzipwind#i.male#i.under50  ) weighted_wind_speed weighted_precipitation , absorb(anon_id monthyear cut_temp) cluster(anon_id monthyear)

eststo gamesexageint






	
	coefplot (gamesexageint , keep(1.male#1.under50#c.highpm) ciopts(recast(rcap) lcolor(red))  mcolor(red) msymbol(D) msize(small)) ///
	(gamesexageint , keep(1.male#0.under50#c.highpm ) ciopts(recast(rcap) lcolor(red))  mcolor(red) msymbol(D) msize(small)) ///
	(gamesexageint , keep(0.male#1.under50#c.highpm ) ciopts(recast(rcap) lcolor(blue))  mcolor(blue) msymbol(D) msize(small)) ///
	(gamesexageint , keep(0.male#0.under50#c.highpm) ciopts(recast(rcap) lcolor(blue))  mcolor(blue) msymbol(D) msize(small)) ///
	, omitted baselevels drop(weighted*) vertical nooffsets levels(95) yline(0)   legend(off)  ///
	coeflabels(1.male#1.under50#c.highpm = "Male < 50" ///
	1.male#0.under50#c.highpm = "Male {&ge} 50" ///
	0.male#1.under50#c.highpm = "Female < 50" ///
	0.male#0.under50#c.highpm = "Female {&ge} 50" ///
	) 
	
	
	graph export $Results/genderage.png, replace
	


	
 egen cut_age = cut(age_sig), at(20(10)81)

 replace cut_age = 70 if age> =80
 replace cut_age = 20 if age<20
	

	
	
		gen ones = 1
		
		
		
		
		
		gen agebins = 1 if cut_age==20
		replace agebins = 2 if cut_age==30
		replace agebins = 3 if cut_age==40
		replace agebins = 4 if cut_age==50
		replace agebins = 5 if cut_age==60
		replace agebins = 6 if cut_age==70
		
		
		label define bins 1 "$<$30" 2 "30"	 3 "40"	 4 "50"	 5 "60"	 6 "$\geq$>70"	

				label values agebins bins 

		
		
		
		reg male i.agebins
		
		eststo agegender
		
		
		
		collapse (sum) Obs = ones (mean) male, by(agebins)
		
		label variable Obs "Observations (000s)"
	
	replace Obs = Obs/1000
	
	
	
	
	coefplot 	(agegender, keep(1.agebins) ciopts(recast(rcap) lcolor(red)) msymbol(D) mcolor(red) msize(large) ) ///
	(agegender, keep(2.agebins) ciopts(recast(rcap) lcolor(orange))  msymbol(D) mcolor(orange) msize(large)) ///
	(agegender, keep(3.agebins) ciopts(recast(rcap) lcolor(gold)) msymbol(D) mcolor(gold) msize(large)) ///
	(agegender, keep(4.agebins) ciopts(recast(rcap) lcolor(green)) msymbol(D) mcolor(green) msize(large)) ///
	(agegender, keep(5.agebins) ciopts(recast(rcap) lcolor(blue)) msymbol(D) mcolor(blue) msize(large)) ///
	( agegender, keep(6.agebins) ciopts(recast(rcap) lcolor("111 000 255")) mcolor("111 000 255") msymbol(D) msize(large) ) ///	
	, vertical levels(95) yline(0) yaxis(2) ytitle("Difference in male share relative to < 30", axis(2)) nooffsets  legend(off) xlabel(, angle(60))  msymbol(D) omitted baselevels  ///
	 coeflabels(1.agebins = "<30" ///
			  2.agebins = "30" ///
			   3.agebins = "40" ///
			  4.agebins = "50" ///
			  5.agebins = "60" ///
			  6.agebins = "{&ge}70" ///
			  )

		
		
		
		addplot: bar Obs agebins if agebins ==1, yaxis(1) bcolor(red%20) xscale(range(1 6))  xlabel(, valuelabel) xtick(6)
		addplot: bar Obs agebins if agebins ==2, yaxis(1) bcolor(orange%20) xscale(range(1 6)) xlabel(, valuelabel) xtick(6)
		addplot: bar Obs agebins if agebins ==3, yaxis(1) bcolor(gold%20) xscale(range(1 6)) xlabel(, valuelabel) xtick(6)
		addplot: bar Obs agebins if agebins ==4, yaxis(1) bcolor(green%20) xscale(range(16)) xlabel(, valuelabel) xtick(6)
		addplot: bar Obs agebins if agebins ==5, yaxis(1) bcolor(blue%20) xscale(range(1 6)) xlabel(, valuelabel) xtick(6)
		addplot: bar Obs agebins if agebins ==6, yaxis(1) bcolor("111 000 255 %20") xscale(range(1 6)) xlabel(, valuelabel) xtick(6) ytitle(Observations (000s), axis(1))
		
		
		
		
		
			graph export $Results/agegender_obs.png, replace


